package cn.wolfcode.car.business.web.controller;

import cn.wolfcode.car.business.domain.CarPackageAudit;
import cn.wolfcode.car.business.query.CarPackageAuditQuery;
import cn.wolfcode.car.business.service.ICarPackageAuditService;
import cn.wolfcode.car.common.base.page.TablePageInfo;
import cn.wolfcode.car.common.web.AjaxResult;
import cn.wolfcode.car.shiro.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/business/carPackageAudit")
public class CarPackageAuditController {

    private String prefix="/business/carPackageAudit";
    @Autowired
    private ICarPackageAuditService carPackageAuditService;
    //去审核列表页面
    @RequestMapping("/listPage")
    private String listPage(){
        return prefix+"/list";
    }
    //分页+过滤
    @RequestMapping("/query")
    @ResponseBody
    private TablePageInfo<CarPackageAudit> query(CarPackageAuditQuery qo){
        return carPackageAuditService.query(qo);
    }
    //去我的待办页面
    @RequestMapping("/todoPage")
    public String todoPage(){
        return prefix+"/todoPage";
    }
    //一样：分页+过滤
    @RequestMapping("/todoQuery")
    @ResponseBody
    private TablePageInfo<CarPackageAudit> todoQuery(CarPackageAuditQuery qo){
        //如果是管理员登录则可以审核所有审核记录表
        if("admin".equalsIgnoreCase(ShiroUtils.getLoginName())){
            return carPackageAuditService.query(qo);
        }
        //查询的必须是当前登录的用户且审核记录表也必须为审核中
        Long loginId = ShiroUtils.getUser().getId();
        qo.setAuditorId(loginId);
        qo.setAuditStatus(CarPackageAudit.STATUS_IN_ROGRESS);
        return carPackageAuditService.query(qo);
    }
    //去审批页面
    @RequestMapping("/auditPage")
    public String auditPage(Long id, Model model){
        model.addAttribute("id",id);//获取审核流程记录单id，为了以后的审批的内容。
        return prefix+"/audit";
    }
    //审批:其实就是通过判断审批的结果，对审核流程记录单和服务单项做一些状态修改。
    @RequestMapping("/audit")
    @ResponseBody
    public AjaxResult audit(Long id,int auditStatus){
        carPackageAuditService.audit(id,auditStatus);
        return new AjaxResult().success("对该服务审核流程单的审批动作已完成！");
    }
    //到我的已办页面
    @RequestMapping("/donePage")
    public String donePage(){
        return prefix+"/donePage";
    }
    //查看我的已办(也就是查询自己已办的信息:因为当前审核人会改变，这个目前只能使用审批时通过额外签名的info)
    @RequestMapping("/doneQuery")
    @ResponseBody
    public TablePageInfo<CarPackageAudit> doneQuery(CarPackageAuditQuery qo){
        qo.setAuditorName(ShiroUtils.getLoginName());//加个条件：根据登录的当前用户名查询审核记录表是否有此人的名字签名
        return carPackageAuditService.query(qo);
    }

}
